/**
 * @file Parameter.cpp
 * @brief 加载yaml文件，并根据参数类别创建结构体
 * @author Rosen (1018477962@qq.com)
 * @version 1.0
 * @date 2021-09-26
 * 
 * @copyright Copyright (c) 2021 by Rosen.
 */
#include "Parameter.h"
#include <assert.h>
#include <opencv2/opencv.hpp>

/**
 * @brief Construct a new Camera Param:: Camera Param object
 *        加载相机相关参数
 * @param path 相机参数yaml文件路径
 */
CameraParam::CameraParam(const std::string &path)
{
    assert(!path.empty());
    cv::FileStorage Cam(path, cv::FileStorage::READ);
    Cam["Width"] >> this->imgWidth;
    Cam["Height"] >> this->imgHeight;
    Cam["FPS"] >> this->FPS;
    Cam["CameraMatrix"] >> this->cameraMatrix;
}
CameraParam cameraParam("../YamlFiles/CameraParam.yaml");

/**
 * @brief Construct a new Dataset Param:: Dataset Param object
 * 
 * @param path 数据集参数yaml文件路径
 */
DatasetParam::DatasetParam(const std::string &path)
{
    assert(!path.empty());
    cv::FileStorage Dat(path, cv::FileStorage::READ);
    Dat["nc"] >> this->nc;
    Dat["names"] >> this->className;
}
DatasetParam datasetParam("../YamlFiles/DatasetParam.yaml");

/**
 * @brief Construct a new Detect Param:: Detect Param object
 * 
 * @param path 检测器参数yaml文件路径
 */
DetectParam::DetectParam(const std::string &path)
{
    assert(!path.empty());
    cv::FileStorage Dec(path, cv::FileStorage::READ);
    Dec["ItemSize"] >> this->ItemSize;
    Dec["ConfThres"] >> this->ConfThres;
    Dec["NMSThres"] >> this->NMSThres;
    Dec["AnchorSize"] >> this->AnchorSize;
}
DetectParam detectParam("../YamlFiles/DetectParam.yaml");

/**
 * @brief Construct a new Strategy Param:: Strategy Param object
 * @param  path 决策器参数yaml文件路径
 */
StrategyParam::StrategyParam(const std::string &path)
{
    assert(!path.empty());
    cv::FileStorage Stra(path, cv::FileStorage::READ);
    Stra["MaxDis"] >> this->maxDis;
}
StrategyParam strategyParam("../YamlFiles/StrategyParam.yaml");

/**
 * @brief Construct a new Robo Param:: Robo Param object
 * 
 * @param path Robot参数yaml文件路径
 */
RoboParam::RoboParam(const std::string &path)
{
    assert(!path.empty());
    cv::FileStorage Robo(path, cv::FileStorage::READ);
    Robo["ModelPath"] >> this->modelPath;
}
RoboParam roboParam("../YamlFiles/RoboParam.yaml");